/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.business;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.common.utils.StringUtils;
import com.neusoft.lohas.modules.ivm.dao.business.RollScreenDao;
import com.neusoft.lohas.modules.ivm.entity.business.RollScreen;

/**
 * 商圈滚屏Service
 * @author Jackie.Liu
 * @version 2015-01-29
 */
@Component
@Transactional(readOnly = true)
public class RollScreenService extends BaseService {

	@Autowired
	private RollScreenDao rollScreenDao;
	
	public RollScreen get(String id) {
		return rollScreenDao.get(id);
	}
	
	public Page<RollScreen> find(Page<RollScreen> page, RollScreen rollScreen) {
		DetachedCriteria dc = rollScreenDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(rollScreen.getTitle())){
			dc.add(Restrictions.like("title", "%"+rollScreen.getTitle()+"%"));
		}
		dc.add(Restrictions.eq(RollScreen.FIELD_DEL_FLAG, RollScreen.DEL_FLAG_NORMAL));
		dc.add(Restrictions.eq("merchant.id", rollScreen.getMerchant().getId()));
		dc.addOrder(Order.asc("sort"));
		return rollScreenDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(RollScreen rollScreen) {
		rollScreenDao.save(rollScreen);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		rollScreenDao.deleteById(id);
	}

}
